function varargout = CollagenMasterGUI(varargin)
% COLLAGENMASTERGUI MATLAB code for CollagenMasterGUI.fig
% Created 2018.7.12 PVT
% Most recent update: 2018.7.13 PVT
%
%      COLLAGENMASTERGUI, by itself, creates a new COLLAGENMASTERGUI or raises the existing
%      singleton*.
%
%      H = COLLAGENMASTERGUI returns the handle to a new COLLAGENMASTERGUI or the handle to
%      the existing singleton*.
%
%      COLLAGENMASTERGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in COLLAGENMASTERGUI.M with the given input arguments.
%
%      COLLAGENMASTERGUI('Property','Value',...) creates a new COLLAGENMASTERGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before CollagenMasterGUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to CollagenMasterGUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help CollagenMasterGUI

% Last Modified by GUIDE v2.5 05-Jul-2018 23:14:47

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @CollagenMasterGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @CollagenMasterGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before CollagenMasterGUI is made visible.
function CollagenMasterGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to CollagenMasterGUI (see VARARGIN)

% Choose default command line output for CollagenMasterGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes CollagenMasterGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = CollagenMasterGUI_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.suffix = get(hObject, 'string');
guidata(hObject, handles);

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.suffix = get(hObject, 'string');
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[handles.filename handles.folder] = uigetfile(handles.suffix);
handles.full_file_path = fullfile(handles.folder, handles.filename);
ImageIN = bfopen(handles.full_file_path);
rawdata(:,:) = (ImageIN{1,1}{1,1});
handles.data = im2double(rawdata);
set(handles.text7, 'String', handles.filename);
guidata(hObject, handles);
handles



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.suffix1 = get(hObject, 'string');
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.suffix1 = get(hObject, 'string');
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.folder = uigetdir();
handles.File = dir([handles.folder '/' handles.suffix1]);
set(handles.text6, 'String', handles.folder);
guidata(hObject, handles);


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.weiner_filt = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox2



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.filter_size = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.filter_size = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.strel_disk = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.strel_disk = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.pixel_size = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.pixel_size = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.erode_cutoff = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.erode_cutoff = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.top_hat_filt = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox1


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[handles.num_pores handles.avg_diameter handles.fibril_content handles.all_diameters] = PoreSize(handles.data, handles.pixel_size, handles.strel_disk, handles.erode_cutoff, handles.top_hat_filt, handles.weiner_filt, handles.filter_size);
set(handles.text12, 'String', strcat('# Pores: ', num2str(handles.num_pores)));
set(handles.text13, 'String', strcat('Avg Diameter: ', num2str(handles.avg_diameter)));
set(handles.text14, 'String', strcat('Fibril Content: ', num2str(handles.fibril_content)));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function checkbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.top_hat_filt = get(hObject, 'value');
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function checkbox2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.weiner_filt = get(hObject, 'value');
guidata(hObject, handles);


% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.weiner_filt1 = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox5



function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.filter_size1 = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.filter_size1 = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit12_Callback(hObject, eventdata, handles)
% hObject    handle to edit12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.strel_disk1 = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit12 as text
%        str2double(get(hObject,'String')) returns contents of edit12 as a double


% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.strel_disk1 = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.top_hat_filt1 = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox6



function edit14_Callback(hObject, eventdata, handles)
% hObject    handle to edit14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.resizing_factor = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit14 as text
%        str2double(get(hObject,'String')) returns contents of edit14 as a double


% --- Executes during object creation, after setting all properties.
function edit14_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.resizing_factor = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit13_Callback(hObject, eventdata, handles)
% hObject    handle to edit13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.pixel_size1 = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit13 as text
%        str2double(get(hObject,'String')) returns contents of edit13 as a double


% --- Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.pixel_size1 = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit15_Callback(hObject, eventdata, handles)
% hObject    handle to edit15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.shift = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit15 as text
%        str2double(get(hObject,'String')) returns contents of edit15 as a double


% --- Executes during object creation, after setting all properties.
function edit15_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.shift = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit16_Callback(hObject, eventdata, handles)
% hObject    handle to edit16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.BW_threshold = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of edit16 as text
%        str2double(get(hObject,'String')) returns contents of edit16 as a double


% --- Executes during object creation, after setting all properties.
function edit16_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.BW_threshold = str2num(get(hObject, 'string'));
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.center_zero = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox7


% --- Executes during object creation, after setting all properties.
function checkbox7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.center_zero = get(hObject, 'value');
guidata(hObject, handles);


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[handles.char_feature_length handles.char_pore_size] = CollagenAutocorrelation(handles.data, handles.pixel_size1, handles.resizing_factor, handles.weiner_filt1, handles.filter_size1, handles.top_hat_filt1, handles.strel_disk1, handles.shift, handles.BW_threshold, handles.center_zero);
set(handles.text29, 'String', strcat('Char Feature Length: ', num2str(handles.char_feature_length)));
set(handles.text30, 'String', strcat('Char Pore Size: ', num2str(handles.char_pore_size)));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function checkbox6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.top_hat_filt1 = get(hObject, 'value');
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function checkbox5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.weiner_filt1 = get(hObject, 'value');
guidata(hObject, handles);


% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.erosion_pore_size = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox8


% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.autocorrelation = get(hObject, 'value');
guidata(hObject, handles);
% Hint: get(hObject,'Value') returns toggle state of checkbox9


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
NF = size(handles.File,1)
handles.num_pores1 = [];
handles.avg_diameter1 = [];
handles.fibril_content1 = [];
handles.char_feature_length1 = [];
handles.char_pore_size1 = []
handles.all_diameters1 = {};
handles.aspect_ratio = [];
for i = 1:NF
    ImageIN = bfopen([handles.folder '/' handles.File(i).name]);
    rawdata(:,:) = (ImageIN{1,1}{1,1}); % for pore size analysis
    image_double = im2double(rawdata);
    if handles.erosion_pore_size == 1
        [handles.num_pores1(i) handles.avg_diameter1(i) handles.fibril_content1(i) handles.all_diameters1{i}] = PoreSize(image_double, handles.pixel_size, handles.strel_disk, handles.erode_cutoff, handles.top_hat_filt, handles.weiner_filt, handles.filter_size);
        % print out all diameters
        fileID = fopen(strcat(handles.File(1).folder, ['/all_diameters_', handles.File(i).name, '_results.txt']), 'w');
        fprintf(fileID, '%8.5f\r\n', handles.all_diameters1{i});
        fclose(fileID);
    end
    if handles.autocorrelation == 1
        [handles.char_feature_length1(i) handles.char_pore_size1(i)] = CollagenAutocorrelation(image_double, handles.pixel_size1, handles.resizing_factor, handles.weiner_filt1, handles.filter_size1, handles.top_hat_filt1, handles.strel_disk1, handles.shift, handles.BW_threshold, handles.center_zero);
    end
    [handles.aspect_ratio(i)] = FindAspectRatio(image_double);
end

% if handles.erosion_pore_size == 1
%     M = horzcat(handles.num_pores1', handles.avg_diameter1', handles.fibril_content1');
%     fileID = fopen(strcat(handles.File(1).folder, '/erosion_pore_size_results.txt'), 'w');
%     fprintf(fileID, '%25s\t %8s\t %8s\t %8s\r\n', 'filename', 'num_pores', 'avg_diameter', 'fibril_content');
%     for i = 1:NF
%         fprintf(fileID, '%s\t %8.5f\t %8.5f\t %8.5f\r\n', handles.File(i).name, M(i,1), M(i,2), M(i,3));
%     end
%     fprintf(fileID, '%12s\t %12s\t %12s\t %12s\t %12s\t %12s\r\n', 'Pixel Size', 'Erode Cutoff', 'Strel Disk', 'Filter Size', 'Top Hat', 'Weiner');
%     fprintf(fileID, '%8.5f\t %8.5f\t %8.5f\t %8.5f\t %8.5f\t %8.5f\r\n', handles.pixel_size, handles.erode_cutoff, handles.strel_disk, handles.filter_size, handles.top_hat_filt, handles.weiner_filt);
%     fclose(fileID);
% end

% if handles.autocorrelation == 1
    AR = handles.aspect_ratio';
    M = horzcat(handles.num_pores1', handles.avg_diameter1', handles.fibril_content1');
    M1 = horzcat(handles.char_feature_length1', handles.char_pore_size1');
    fileID = fopen(strcat(handles.File(1).folder, '/analysis_results.txt'), 'w');
    fprintf(fileID, '%25s\t %8s\t %8s\t %8s\t %8s\t %8s\r\n', 'filename', 'char_feature_length', 'char_pore_size', 'avg_diameter', 'fibril_content', 'aspect_ratio');
    for i = 1:NF
        fprintf(fileID, '%s\t %8.5f\t %8.5f\t %8.5f\t %8.5f\t %8.5f\r\n', handles.File(i).name, M1(i,1), M1(i,2), M(i,2), M(i,3), AR(i));
    end
    fclose(fileID);
    'donezo'
% end

% --- Executes during object creation, after setting all properties.
function checkbox8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.erosion_pore_size = get(hObject, 'value');
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function checkbox9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to checkbox9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.autocorrelation = get(hObject, 'value');
guidata(hObject, handles);
